package sessionBean;

import java.util.ArrayList;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import entityBean.Pacchetto;

/**
 * Session Bean implementation class GestPaccCliente
 */
@Stateless(name="GestPaccCliente")
@Remote(GestPaccClienteRemote.class)
public class GestPaccCliente implements GestPaccClienteRemote {
	
	@PersistenceContext(unitName="cvproject") 
	private EntityManager manager;

    /**
     * Default constructor. 
     */
    public GestPaccCliente() {
        // TODO Auto-generated constructor stub
    }

	@Override
	public ArrayList<Pacchetto> visualizza() {
		
		//Prelevo i pacchetti presenti nel db
		
		try {
			
			String s ="FROM pacchetto p";
			Query q = manager.createQuery(s);
			
			ArrayList<Pacchetto> listaPacchetti = new ArrayList<Pacchetto>(q.getResultList());
			
			return listaPacchetti;
			
		}
		catch(EntityNotFoundException e) {
			
			return null;
			
		}
	
	}

}
